Shortest Length Subarray Sum

Easy

Question

Find the length of the shortest contiguous subarray in an array of positive integers that sum up to at least the given target value.

If there are no subarrays that add up to the target value, then return 0.

Input: nums = [2, 3, 1, 1, 3, 4], target = 6

Output: 2

The shortest contiguous subarray that sums up to at least 6 is [3, 4] which has a length of 2.

Input: nums = [1, 5, 1], target = 4

Output: 1

The shortest contiguous subarray that sums up to at least 4 is [5] which has a length of 1.

Input: nums = [1, 1, 1], target = 4

Output: 0

There are no contiguous subarrays that can add up to 4.

Clarify the problem

What are some questions you'd ask an interviewer?

Understand the problem

What is the shortest length of a contiguous subarray within this array that sums up to 8? [5, 2, 3, 3, 2, 1]
0
1
2
3

Login or signup to save your code.

Notes